package com.dreamtour.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dreamtour.entity.Advertisements;
import com.dreamtour.entity.Feedbacks;
import com.dreamtour.entity.Services;
import com.dreamtour.service.IFeedbacksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xls
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/feedbacks")
public class FeedbacksController {
    @Autowired
    private IFeedbacksService feedbacksService;

    @RequestMapping("/getReports")
    public List<Feedbacks> getReports() {
        return feedbacksService.getReports();
    }

    @RequestMapping("/getSuggestions")
    public List<Feedbacks> getSuggestions() {
        return feedbacksService.getSuggestions();
    }

    @RequestMapping("/getByName")
    public List<Feedbacks> getByName(String feedbackId) {
        QueryWrapper<Feedbacks> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("feedbackId", feedbackId);
        List<Feedbacks> list = feedbacksService.list(queryWrapper);
        return list;
    }

    @GetMapping("/filter1")
    public ResponseEntity<Map<String, Object>> filterFeedbacks1(
            @RequestParam(required = false) String handleStatus) {

        QueryWrapper<Feedbacks> queryWrapper = new QueryWrapper<>();

        // 添加验证状态筛选条件
        if (handleStatus != null && !handleStatus.isEmpty()) {
            // 假设qualifyStatus的值是"0", "1", "2"分别代表，已通过，待审核,未通过
            // 这里需要根据实际的数据库字段类型和值进行调整
            queryWrapper.eq("handleStatus", handleStatus);
        }

        // 查询符合条件的旅行社
        List<Feedbacks> filteredServices = feedbacksService.list(queryWrapper);

        // 准备返回数据
        Map<String, Object> response = new HashMap<>();
        response.put("feedbacks", filteredServices);

        return ResponseEntity.ok(response);
    }

    @GetMapping("/filter2")
    public ResponseEntity<Map<String, Object>> filterFeedbacks2(
            @RequestParam(required = false) String feedbackType) {

        QueryWrapper<Feedbacks> queryWrapper = new QueryWrapper<>();

        // 添加验证状态筛选条件
        if (feedbackType != null && !feedbackType.isEmpty()) {
            // 假设qualifyStatus的值是"0", "1", "2"分别代表，已通过，待审核,未通过
            // 这里需要根据实际的数据库字段类型和值进行调整
            queryWrapper.eq("feedbackType", feedbackType);
        }

        // 查询符合条件的旅行社
        List<Feedbacks> filteredServices = feedbacksService.list(queryWrapper);

        // 准备返回数据
        Map<String, Object> response = new HashMap<>();
        response.put("feedbacks", filteredServices);

        return ResponseEntity.ok(response);
    }

    @RequestMapping("/update")
    public boolean update(@RequestBody Feedbacks feedbacks) {
        boolean b = feedbacksService.updateById(feedbacks);
        return b;
    }

    @RequestMapping("/updateByBatch")
    public boolean updateByBatch(@RequestBody List<Feedbacks> feedbackList) {
        boolean b = feedbacksService.updateBatchById(feedbackList);
        return b;
    }

    @RequestMapping("/getFeedbacksCountByMonth")
    public ResponseEntity<List<Map<String, Object>>> getFeedbacksCountByMonth() {
        List<Map<String, Object>> monthlyCounts = feedbacksService.countFeedbacksByMonth();

        // 直接返回原始的统计数据列表
        return ResponseEntity.ok(monthlyCounts);
    }

    @GetMapping("/check")
    public ResponseEntity<Feedbacks> getServiceDetails(@RequestParam Integer feedbackId) {
        Feedbacks feedbacks = feedbacksService.findById(feedbackId);
        if (feedbacks != null) {
            return ResponseEntity.ok(feedbacks);
        } else {
            return ResponseEntity.notFound().build();
        }
    }


}